1. Field of the Invention
The present invention relates to video encoding systems, such as MPEG and MPEG-2 video encoders, and more particularly, to video encoders in which quantization levels in a lossy compression method are initially set before a re-encoding process and then changed during the re-encoding process to match a target bit rate or total bit length.
2. Discussion of the Background
Encoding digital video for MPEG, MPEG-2 and similar standards involves several steps which result in a compressed digital representation of the original frames. Each frame is partitioned into blocks of video data called macroblocks, and a combined row of macroblocks is called a slice. Sets of macroblocks can be analyzed and compressed individually, and depending on the resulting compression ratio, compression parameters for the next set of macroblocks can be changed to match a target bit length.
Using redundant spatial and temporal information from the original video signal, slices of macroblocks are combined to create lossy, compressed representations of the original video. Compressing a frame requires that the pixel data of each macroblock be converted by a discrete cosine transformation (DCT) to a DC coefficient and a series of AC coefficients. The DC and AC coefficients are collectively known as DCT coefficients. The DCT coefficients are then quantized, or rounded, using a quantization level, or q-level, assigned to each macroblock or slice. Quantization levels are coded using a table identifier and an index into a table. The table identifier is an indication of whether a linear or non-linear table, called a quantization scale table, is to be used, and the index, called a quantization scale code, specifies an offset into the indicated table. Therefore, desired quantization levels must be mapped to the closest quantization levels that are available in the current quantization scale table, i.e., linear or non-linear.
Since the quantization/rounding process truncates the precision of the coefficients, it causes a substantial portion of the loss in the image coding process. The amount of loss can be controlled by varying the quantization levels used. By decreasing the quantization level of a set of macroblocks, more bits are used to represent the changes, i.e., DCT coefficients, in the set of macroblocks, allowing a more accurate representation of the frame. The opposite is also true, i.e., increasing the quantization level reduces the number of bits used to code a set of macroblocks and results in coarser representations of changes in the frame, thus reducing image quality. The DCT coefficients are run-length encoded after being quantized, and the run-length codes are then encoded using variable length Huffman codes. When the last DCT coefficients in a series are a continuous set of zeroes, the remaining coefficients are not encoded, but rather a special end-of-block symbol that further compresses the frame is used. The use of varying quantization scales, variable length codes and a varying number of coefficients per macroblock results in frames with greatly differing lengths. Therefore, the resulting video must be checked for underflow and overflow errors to assure compliance with its corresponding video standard.
Unfortunately, the encoding process can introduce visual artifacts by quantizing changes too coarsely in portions of an image. To correct artifacts, a series of frames can be changed during a post-production phase to alter the quantization levels of different areas of the frames. This changes the number of bits and the accuracy with which changes in portions of the frames can be coded. Since the human eye is less likely to see quantization errors in high spatial frequency areas than in low spatial frequency areas, bits from high spatial frequency areas can be reallocated to low spatial frequency areas. This allows finer quantization in low frequency areas, thus reducing quantization errors. However, re-encoding a video sequence without constraining its resultant re-encoded length would require that the video syntax be rechecked for new underflow and overflow problems. In addition, to maintain a contiguous video stream when the re-encoded length differs from the original length, the remaining previously stored video must be shifted forward or backward on its digital storage medium depending on whether there are fewer or more bits, respectively, in the re-encoded video. Shifting the video would require reading and rewriting every block of video after the edited frames, thus, on average, requiring several tens of megabytes to be copied for a full-length movie.